import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/service/config_service.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/app_icons.dart';
import 'package:ball_lion/routes/routes.dart';
import 'package:ball_lion/utils/widget_utils.dart';
import 'package:ball_lion/module/mine/my_notify_desc1_page.dart';
import 'package:ball_lion/module/mine/widgets/list_cell_box.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'package:ball_lion/widgets/ball_appbar.dart';

class MyNotifySettingPage extends StatefulWidget {
  const MyNotifySettingPage({super.key});

  @override
  State<MyNotifySettingPage> createState() => _MyNotifySettingPageState();
}

class _notifyItem {}

class _MyNotifySettingPageState extends State<MyNotifySettingPage> {
  final config = Get.find<ConfigService>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BallAppBar(title: "通知设置"),
      backgroundColor: Colours.scaffoldBg,
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
        child: Column(
          children: [
            ListCellBox(children: [
              cell("消息通知设置",
                  right: switchBtn(config.pushConfig.pushAll == 1, (p0) {
                    config.pushConfig.pushAll = p0 ? 1 : 0;
                    update();
                  }))
            ]),
            desc("开启后，您可以接收到最新消息动态"),
            if (config.pushConfig.pushAll == 1) ...[
              ListCellBox(children: [
                cell("足球比赛通知",
                        right: tailDesc(config.zqConfig.zqPush1 == 1
                            ? config.zqConfig.getPushConfigCount()
                            : '0/7'))
                    .tap(() {
                  Get.toNamed(Routes.zqPushConfig);
                }),
                const Divider(height: 0.5, color: Colours.greyEE)
                    .marginSymmetric(horizontal: 12),
                cell("篮球比赛通知",
                        right: tailDesc(config.lqConfig.lqPush1 == 1
                            ? config.lqConfig.getPushConfigCount()
                            : '0/2'))
                    .tap(() {
                  Get.toNamed(Routes.lqPushConfig);
                }),
              ]),
              desc("未关注比赛将不会收到任何比赛通知"),
              ListCellBox(children: [
                cell("资讯新闻",
                    right: switchBtn(config.pushConfig.pushNews == 1, (p0) {
                      config.pushConfig.pushNews = p0 ? 1 : 0;
                      update();
                    }))
              ]),
              desc("关闭后，将不会收到资讯消息通知"),
              ListCellBox(children: [
                cell("关注专家提醒",
                    right: switchBtn(config.pushConfig.pushExpert == 1, (p0) {
                      config.pushConfig.pushExpert = p0 ? 1 : 0;
                      update();
                    }))
              ]),
              desc("开启后，关注专家发表方案，第一时间通知您"),
              ListCellBox(children: [
                cell("夜间免打扰模式",
                    right: switchBtn(config.pushConfig.pushInNight == 1, (p0) {
                      config.pushConfig.pushInNight = p0 ? 1 : 0;
                      update();
                    }))
              ]),
              desc("开启后，您在夜间(23:00至次日7:00)将不会收到推送信息"),
            ],
            ListCellBox(children: [
              cell("底部导航栏震动",
                  spacer: false,
                  right: Expanded(
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 4,
                        ),
                        AppIcons.iconQuery().tap(() {
                          Get.to(() => const MyNotifyDesc1Page());
                        }),
                        const Spacer(),
                        switchBtn(config.pushConfig.bottomVibration == 1, (p0) {
                          config.pushConfig.bottomVibration = p0 ? 1 : 0;
                          update();
                        })
                      ],
                    ),
                  ))
            ]),
          ],
        ),
      ),
    );
  }

  Widget desc(String data) => Container(
        padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
        margin: const EdgeInsets.only(bottom: 12),
        alignment: Alignment.centerLeft,
        child: QsText(data, color: Colours.grey66, fontSize: 13),
      );

  Widget tailDesc(String m) => Row(
        children: [
          QsText(m, color: Colours.grey66),
          const SizedBox(
            width: 8,
          ),
          AppIcons.rightArrow()
        ],
      );

  Widget switchBtn(bool v, void Function(bool) onChanged) => CupertinoSwitch(
      activeColor: Colours.main, value: v, onChanged: onChanged);

  Widget cell(String data, {Widget? right, bool spacer = true}) => Container(
        height: 52,
        padding: const EdgeInsets.symmetric(horizontal: 12),
        child: Row(
          children: [
            QsText(data),
            if (spacer) const Spacer(),
            right ?? Container()
          ],
        ),
      );
}
